<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1 id="clock"></h1>
    <script type="text/javascript">
      //   var int = setInterval('clock()', 1000) //函数名 每隔多久执行 毫秒单位
      //   function clock() {
      //     var d = new Date()
      //     var t = d.toLocaleTimeString()
      //     document.getElementById('clock').innerHTML = t
      //   }

      var int = setTimeout(function () {
        //多少秒之后  仅执行一次
        var d = new Date()
        var t = d.toLocaleTimeString()
        document.getElementById('clock').innerHTML = t
      }, 3000) //函数名 每个多久执行 毫秒单位
    </script>

    <button onclick="clearInterval(int)">停止</button>
  </body>
  <script>
    var dateObj = new Date()
    console.log(dateObj.getDate()) //某天
    console.log(dateObj.getDay()) //某周的星期几
    console.log(dateObj.getFullYear()) // 年份
    console.log(dateObj.getMonth() + 1)
    console.log(dateObj.getTime())
  </script>
</html>
